/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  6
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      snappyHexMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

// Which of the steps to run
castellatedMesh true;    // make basic mesh ?
snap            true;    // decide to snap back to surface ?
addLayers       false;   // decide to add viscous layers ?


geometry // Load in STL files here
{
	inlet.stl {type triSurfaceMesh; name inlet;}
	outlet.stl {type triSurfaceMesh; name outlet;}
	wall_heatplate.stl {type triSurfaceMesh; name wall_heatplate;}
	wall_lower.stl {type triSurfaceMesh; name wall_lower;}
	wall_nozzle.stl {type triSurfaceMesh; name wall_nozzle;}
	wall_orificeplate.stl {type triSurfaceMesh; name wall_orificeplate;}
        fullbody.stl {type triSurfaceMesh; name fullbody;}
};

castellatedMeshControls
{
    maxLocalCells 3000000;  //max cells per CPU core
    maxGlobalCells 1000000; //max cells to use before mesh deletion step
    minRefinementCells 10;  //was 0 - zero means no bad cells are allowed during refinement stages
    maxLoadUnbalance 0.10;
    nCellsBetweenLevels 1;  // expansion factor between each high & low refinement zone

    // Explicit feature edge refinement
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    features // taken from STL from each .eMesh file created by "SurfaceFeatureExtract" command
    (
        {file "inlet.eMesh"; level 0;} 
        {file "outlet.eMesh"; level 0;} 
        {file "wall_heatplate.eMesh"; level 0;}
        {file "wall_lower.eMesh"; level 0;}  
        {file "wall_nozzle.eMesh"; level 0;} 
        {file "wall_orificeplate.eMesh"; level 0;} 
    );

    // Surface based refinement
    // ~~~~~~~~~~~~~~~~~~~~~~~~

    refinementSurfaces // Surface-wise min and max refinement level
    {
	inlet {level (0 0);}
        outlet {level (0 0);}
	wall_heatplate {level (1 1);} 
	wall_lower {level (0 0);} 
	wall_orificeplate {level (0 0);} // was 4 4
	wall_nozzle {level (0 0);} // was 4 4
    }  


    resolveFeatureAngle 80;  // Resolve sharp angles // Default 30
    refinementRegions        // In descending levels of fine-ness
    {
    }
    locationInMesh (0.06 0.003 0.06);  //to decide which side of mesh to keep **
    allowFreeStandingZoneFaces true;
}


// Settings for the snapping.
snapControls
{
    nSmoothPatch 3;
    tolerance 4.0;
    nSolveIter 30;
    nRelaxIter 5;
    nFeatureSnapIter 15; // default is 10
    
// New settings from openfoam 2.2 onwards for SHMesh

implicitFeatureSnap false; // default is false - detects without doing surfaceFeatureExtract
explicitFeatureSnap true; // default is true
multiRegionFeatureSnap false; // deafault is false - detects features between multiple surfaces

}



// Settings for the layer addition.
addLayersControls //add the PATCH names from inside the STL file so STLpatchName_insideSTLName 
{
    relativeSizes false; // was true
    layers
    {
	wall_heatplate
         	{nSurfaceLayers 15;} // was 3
	wall_lower
         	{nSurfaceLayers 15;} // was 3
    }

    expansionRatio 1.24;
    finalLayerThickness 0.0020319; //was 0.00016
    minThickness 0.0001; //was 0.00008
    nGrow 0; // was 1 


    // Advanced settings

    featureAngle 80; // was 70 //- When not to extrude surface. 0 is flat, 90 is right angle.
    nRelaxIter 3;  //- Max# of snapping relaxation iter. Should stop before upon reaching a correct mesh.
    nSmoothSurfaceNormals 1;  // Number of smoothing iterations of surface normals
    nSmoothNormals 3; // Number of smoothing iterations of interior mesh movement direction
    nSmoothThickness 10;  // Smooth layer thickness over surface patches
    maxFaceThicknessRatio 0.5; // Stop layer growth on highly warped cells
    maxThicknessToMedialRatio 0.3; // Reduce layer growth where ratio thickness to medial distance is large
    minMedianAxisAngle 130;  // Angle used to pick up medial axis points
    nBufferCellsNoExtrude 0;   // Create buffer region for new layer terminations
    nLayerIter 50; // Overall max number of layer addition iterations
}



// Generic mesh quality settings. At any undoable phase these determine
// where to undo.
meshQualityControls
{
    maxNonOrtho 65;
    maxBoundarySkewness 20;
    maxInternalSkewness 4;
    maxConcave 80;
    minFlatness 0.5;
    minVol 1e-13;
    minTetQuality 1e-9;
    minArea -1;
    minTwist 0.02;
    minDeterminant 0.001;
    minFaceWeight 0.02;
    minVolRatio 0.01;
    minTriangleTwist -1;

    // Advanced

    nSmoothScale 4;
    errorReduction 0.75;
}

// Advanced

debug 0;


// Merge tolerance. Is fraction of overall bounding box of initial mesh.
// Note: the write tolerance needs to be higher than this.
mergeTolerance 1E-6;


// ************************************************************************* //
